package com.syuswe.qimo_02.service.impl;

import com.syuswe.qimo_02.mapper.EmpMapper;
import com.syuswe.qimo_02.pojo.Emp;
import com.syuswe.qimo_02.pojo.PageBean;
import com.syuswe.qimo_02.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author n7c.swe
 * {@code @date} 2024-05
 */
@Service
public class EmpServiceImpl implements EmpService {

    private final EmpMapper empMapper;
    @Autowired
    public EmpServiceImpl(EmpMapper empMapper){
        this.empMapper = empMapper;
    }


    @Override
    public PageBean page(Integer page, Integer pageSize) {

        // 1.获取总记录数
        Long count = empMapper.count();

        // 2.获取分页查询结果列表
        int start = (page - 1) * pageSize;
        List<Emp> empList = empMapper.page(start, pageSize);

        // 3.封装到PageBean对象中并返回
        return new PageBean(count, empList);

    }

    @Override
    public void insertEmp(Emp emp) {
        empMapper.insert(emp);
    }

}
